package com.archerdu.commons.taglib;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.log4j.Logger;

import com.archerdu.base.dao.IPage;
import com.archerdu.commons.util.HtmlUtil;

/**
 * 生成分页标签
 * 
 * @projectName springDemo
 * @description 生成分页标签
 * @author archer du
 * @createDate 2013年9月27日 下午5:22:14
 * @updateUser dxf
 * @updateDate 2013年9月27日 下午5:22:14
 * @updateRemark 新建
 * @version 0.0.1
 */
public class PageTag extends TagSupport {

    private static final long   serialVersionUID = -2674115201193700773L;
    private static final Logger LOG              = Logger.getLogger(PageTag.class);

    private String              url;
    private int                 showNums;
    private IPage<Object>       page;

    @Override
    public int doStartTag() {
        if (null == page) {
            LOG.error("page is null");
            return SKIP_BODY;
        }

        JspWriter out = this.pageContext.getOut();
        try {
            out.println(HtmlUtil.pageTag(url, page, showNums, ""));
        } catch (IOException e) {
            LOG.error(e.getMessage(), e);
        }
        return SKIP_BODY;
    }

    @Override
    public int doEndTag() throws JspException {
        return EVAL_PAGE;
    }

    @Override
    public void release() {
        super.release();
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public int getShowNums() {
        return showNums;
    }

    public void setShowNums(int showNums) {
        this.showNums = showNums;
    }

    public IPage<Object> getPage() {
        return page;
    }

    public void setPage(IPage<Object> page) {
        this.page = page;
    }
}
